package cn.arikeky.controller;

import cn.arikeky.basic.util.AjaxResult;
import cn.arikeky.domain.Movie;
import cn.arikeky.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/movie")
public class MovieController {

    @Autowired
    private MovieService movieService;

    // 查询全部
    @GetMapping
    public List<Movie> findAll(){
        return movieService.findMAll();
    }

    // 添加  修改
    @PutMapping
    public AjaxResult addAndUpdate(@RequestBody Movie movie){
        if (null == movie.getM_id()){
            movieService.addM(movie);
        } else {
            movieService.updateM(movie);
        }
        return  AjaxResult.me().success();
    }

    // 删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        movieService.deleteM(id);
        return  AjaxResult.me().success();
    }

    // 根据id查询
    @GetMapping("/{id}")
    public Movie findById(@PathVariable("id") Long id){
        return movieService.findMById(id);
    }
}
